package com.szp.spCloud.mail.controller;

import com.szp.spCloud.mail.util.SimpleMailSender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/email")
public class MailController {
    Logger logger = LoggerFactory.getLogger(MailController.class);
    @RequestMapping("/{email}/{code}")
    public boolean sendEmail(@PathVariable String email, @PathVariable String code){
        try{
            SimpleMailSender.sendMessage("smtp.163.com", "szphust@163.com",
                    "SRRHEPDQOIGXJVEA", email, "auth_code",
                    code,
                    "text/html;charset=gb2312");
            return true;
        }catch (Exception e){
            logger.error("发送又见到{}失败{}", email,e);
            return false;
        }
    }

    @RequestMapping("/test")
    public boolean test(){
        return true;
    }
}
